<template>
    <div class="Addhardware">
        <Addtitle>添加门禁</Addtitle>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <div class="frombox">
                    <el-form-item label="所属社区:" prop="community" class="community">
                        <el-select v-model="ruleForm.community" placeholder="请选择所属社区">
                        <el-option label="小区一" value="shanghai"></el-option>
                        <el-option label="小区二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="设备类型:" prop="type" class="type">
                        <el-select v-model="ruleForm.type" placeholder="请选择设备类型">
                        <el-option label="类别一" value="shanghai"></el-option>
                        <el-option label="类别二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="门禁名称:" prop="type" class="type">
                        <el-select v-model="ruleForm.type" placeholder="请选择门禁名称">
                        <el-option label="类别一" value="shanghai"></el-option>
                        <el-option label="类别二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="配置码:" prop="type" class="type">
                        <el-select v-model="ruleForm.type" placeholder="请选择配置码">
                        <el-option label="类别一" value="shanghai"></el-option>
                        <el-option label="类别二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="状态：" prop="resource" class="resource">
                        <el-radio-group v-model="ruleForm.resource">
                        <el-radio label="启用"></el-radio>
                        <el-radio label="禁用"></el-radio>
                        </el-radio-group>
                    </el-form-item>
                </div>
                <div class="buttonbox">
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('ruleForm')" class="savebutton">保存</el-button>
                        <el-button @click="resetForm('ruleForm')" class="reasetbutton">重置</el-button>
                    </el-form-item>
                </div>
            </el-form>
    </div>
</template>

<script>
import Addtitle from '../components/Addtitle.vue'
export default {
    components:{
        Addtitle
    },
    data() {
      return {
        ruleForm: {
          community:'',     //选择小区
          type:'',          //设备类别
          name: '',         //设备名称
          position:'',      //设备位置
          resource: '',     //状态
        },
        rules: {
          community:[
            { required: true, message: '请选择小区', trigger: 'change' }
          ],
          type:[
            { required: true, message: '请选择设备类别', trigger: 'change' }
          ],
          name: [
            { required: true, message: '请输入设备名称', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          position:[
            { required: false, message: '请输入设备位置', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          resource: [
            { required: false, message: '请选择状态', trigger: 'change' }
          ],
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
            console.log('提交')
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        console.log('取消')
        this.$refs[formName].resetFields(); //清空
      }
    }
}
</script>

<style lang="scss" scoped>
    .Addhardware{
        width: 1260px;  /* 最大1265px */ 
        margin: auto;
        height: 80vh;
        overflow: scroll;
        scrollbar-width: none;
        background-color: #fff;
        border: 1px solid rgba(233, 233, 233, 1);
        .frombox{
            width: 520px;
            padding-left: 200px;
            padding-top: 50px;
            .community,.type,.name,.position,.resource{
                width: 400px;
                ::v-deep .el-form-item__content{
                    margin-left: 120px !important;
                }
                ::v-deep .el-input__inner{
                    width: 400px;
                    height: 35px;
                }
            }
        }
        .buttonbox{
            width: 100%;
            height: 100px;
            border-top: 1px solid rgb(242, 242, 242);
            display: flex;
            justify-content: center;
            align-items: center;
            ::v-deep .el-form-item{
                margin-bottom: 0;
            }
            ::v-deep .el-form-item__content{
                margin-left: 0 !important;
            }
            .savebutton,.reasetbutton{
                width: 140px;
                height: 40px;
                cursor: pointer;
            }
            .savebutton{
                background-color: #0079fe;
            }
            .reasetbutton{
                border-color: #0079fe;
                color: #0079fe;
                margin-left: 20px;
            }
            .savebutton:hover{
                background-color: #3394fe !important;
                color: #fff !important;
            }
            .reasetbutton:hover{
                border-color: #3394fe !important;
                color: #3394fe !important;
                background-color: #fff !important;
            }
        }
    }
</style>